package com.bear.hospital.service.login.handle.strategy;

import com.bear.hospital.entity.LoginInfo;
import com.bear.hospital.pojo.LoginMap;
import com.bear.hospital.pojo.Patient;
import com.bear.hospital.service.login.handle.LoginStrategy;
import com.bear.hospital.service.patient.PatientService;
import com.bear.hospital.utils.JwtUtil;
import com.bear.hospital.utils.ResponseData;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author： zmwx
 * @Date： 2025/1/23 17:15
 * @Describe：
 */
@Component
public class LoginPatient implements LoginStrategy {
    @Override
    public String getType() {
        return "patient";
    }

    @Resource
    private PatientService patientService;

    @Override
    public ResponseData login(LoginMap loginInfo) {
        Patient patient = patientService.login(loginInfo.getTid(), loginInfo.getPassword());
        if (patient != null) {
            Map<String, String> map = new HashMap<>();
            map.put("pName", patient.getPName());
            map.put("pId", String.valueOf(patient.getPId()));
            map.put("pCard", patient.getPCard());
            String token = JwtUtil.getToken(map);
            map.put("token", token);
            map.put("loginUrl", loginInfo.getLoginUrl());
            map.put("imgUrl",patient.getProfilePhotoUrl());
            //response.setHeader("token", token);
            return ResponseData.success("登录成功", map);
        } else {
            return ResponseData.fail("登录失败，密码或账号错误");
        }
    }

    @Override
    public ResponseData setProfilePhoto(LoginInfo loginInfo, String phoneUrl) {
        return null;
    }

    @Override
    public void addUser(LoginMap loginMap) {

    }
}
